package com.nghia.controller;

import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.primefaces.event.RowEditEvent;

import com.nghia.dao.UserDaoImpl;
import com.nghia.domain.Users;
import com.nghia.tabledatamodel.UsersDataModel;

public class ManageUsers {
	private UserDaoImpl userDaoImpl;
	private List<Users> users;
	private Users[] selectedUsers;
	private UsersDataModel usersDataModel;

	public List<Users> getUsers() {
		return users;
	}

	public void setUsers(List<Users> users) {
		this.users = users;
	}

	public void setUserDaoImpl(UserDaoImpl userDaoImpl) {
		this.userDaoImpl = userDaoImpl;
	}

	public UserDaoImpl getUserDaoImpl() {
		return userDaoImpl;
	}

	public Users[] getSelectedUsers() {
		return selectedUsers;
	}

	public void setSelectedUsers(Users[] selectedUsers) {
		this.selectedUsers = selectedUsers;
	}

	public UsersDataModel getUsersDataModel() {
		return usersDataModel;
	}

	public void setUsersDataModel(UsersDataModel usersDataModel) {
		this.usersDataModel = usersDataModel;
	}

	public void onEdit(RowEditEvent event) {
		Users users=(Users) event.getObject();
		FacesMessage msg = new FacesMessage("User Edited",
				users.getUserId() + "");
		FacesContext.getCurrentInstance().addMessage(null, msg);
		userDaoImpl.update(users);
	}

	public void onCancel(RowEditEvent event) {
		FacesMessage msg = new FacesMessage("Users Cancelled",
				((Users) event.getObject()).getUserId() + "");
		FacesContext.getCurrentInstance().addMessage(null, msg);
	}

}
